/*! \file UnicodeConverter_win32.cpp
 *	\brief
 *
 *	created:	2010/08/08
 *	created:	8:8:2010   19:16
 *	filename: 	C:\Users\venn\Documents\projects\tactics-engine\libs\utils\win32\UnicodeConverter.cpp
 *	file path:	C:\Users\venn\Documents\projects\tactics-engine\libs\utils
 *	file base:	UnicodeConverter
 *	file ext:	cpp
 *	author:		Vitalii Trubchaninov
 *				venngraydog@gmail.com
 */
#include "utils/stdafx.h"

#include <stdlib.h>

#include "utils/UnicodeConverter.h"

namespace tt{
namespace utils{

namespace impl{

Size from_ansi(CharW* dst, Size dstSize, const Char* src, Size srcSize)
{
	return MultiByteToWideChar(CP_ACP, 0, src, (Int)srcSize, dst, (Int)dstSize);
}

Size from_ansi_count(const Char* src, Size srcSize)
{
	return from_ansi(NULL, 0, src, srcSize);
}

Size to_ansi(Char* dst, Size dstSize, const CharW* src, Size srcSize)
{
	BOOL usedDefaultChar = false;
	return WideCharToMultiByte(CP_ACP, 0, src, (Int)srcSize, dst, (Int)dstSize, "+", &usedDefaultChar);
}

Size to_ansi_count(const CharW* src, Size srcSize)
{
	return to_ansi(NULL, 0, src, srcSize);
}

Size from_utf8(CharW* dst, Size dstSize, const Char* src, Size srcSize)
{
	return MultiByteToWideChar(CP_UTF8, 0, src, (Int)srcSize, dst, (Int)dstSize);
}

Size from_utf8_count(const Char* src, Size srcSize)
{
	return from_utf8(NULL, 0, src, srcSize);
}

Size to_utf8(Char* dst, Size dstSize, const CharW* src, Size srcSize)
{
	BOOL usedDefaultChar = false;
	return WideCharToMultiByte(CP_UTF8, 0, src, (Int)srcSize, dst, (Int)dstSize, "+", &usedDefaultChar);
}

Size to_utf8_count(const CharW* src, Size srcSize)
{
	return to_utf8(NULL, 0, src, srcSize);
}

} //namespace impl

} //namespace utils
} //namespace tt
